require 'csv'

class AddGeoStuff < ActiveRecord::Migration
  def self.up
     create_table :cities do |t|
        t.column :created_at,   :timestamp, :null => false
        t.column :name,       :string
        t.column :latitude,   :float, :null => false
        t.column :longitude,  :float, :null => false
     end

     add_index :cities,         [:latitude, :longitude], :unique

     # an item is a problem or a resource (possibly an available person) at a particular place
     # it may be stuck at that place or it may follow the movements of a particular agent
     create_table :items do |t|
        t.column :created_at,   :timestamp, :null => false
        t.column :type,         :string,    :null => false    # problem, resource
        t.column :category,     :string,    :null => false
        t.column :data,         :text
        t.column :start_at,     :timestamp
        t.column :done_at,      :timestamp
        t.column :user_id,      :integer
        t.column :location_follows_author, :boolean, :default => 1

        t.column :city_id,      :integer
        t.column :latitude,     :float,   :null => false
        t.column :longitude,    :float,   :null => false
        t.column :location,     :string,    :null => false
     end

     add_index :items,          :city_id
     add_index :items,          :start_at
     add_index :items,          :created_at
  end
  def self.down
  end
end
